package com.ruitu.mall_98_2.mvp.presenter;

import com.beanu.arad.utils.Logg;
import com.beanu.arad.utils.ToastUtils;
import com.ruitu.mall_98_2.mvp.contract.OrderDetailsContract;
import com.ruitu.router_module.bean.api.BaseResult;
import com.ruitu.router_module.bean.api.SubscriberImpl;
import com.ruitu.router_module.bean.order.OrderDetail;

public class OrderDetailsPresenter extends OrderDetailsContract.Presenter {
    @Override
    public void orderDetailsInfo(String orderId) {
        mModel.orderDetailsInfo(orderId)
                .subscribe(new SubscriberImpl<BaseResult<OrderDetail>>() {
                    @Override
                    public void onError(Throwable e) {
                        Logg.i(e.toString());
                        mView.setFail();
                        mView.hideProgress();
                        ToastUtils.showShort("获取订单详情失败");
                    }

                    @Override
                    public void onNext(BaseResult<OrderDetail> baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setData(baseResult.getData());
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void qrsh(String odId) {
        mModel.qrsh(odId)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("确认收货失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setSuc();
                            ToastUtils.showShort(baseResult.getMsg());
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void deleteOrder(String orderId) {
        mModel.deleteOrder(orderId)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("删除订单失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setSuc();
                            ToastUtils.showShort(baseResult.getMsg());
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void invitationCollage(String goodsId) {
        mModel.invitationCollage(goodsId)
                .subscribe(new SubscriberImpl<BaseResult<String>>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("邀请异常");
                    }

                    @Override
                    public void onNext(BaseResult<String> baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setInvitationSuc(baseResult.getData());
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

}
